package SwingComponents;

import Controllers.ArkanoidController;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.BorderFactory;
import javax.swing.SpringLayout;

public class ArkanoidPanel extends TransparentPanel {

    private int width = 501;
    private int height = 701;
    private ArkanoidController arkanoidController;
    private JDoubleBufferedPanel boardPanel;
    private JDoubleBufferedPanel lifePanel;
    private JDoubleBufferedPanel scorePanel;
    private JDoubleBufferedPanel timePanel;
    private JDoubleBufferedPanel topBoundaryPanel;
    private JDoubleBufferedPanel leftBoundaryPanel;
    private JDoubleBufferedPanel rightBoundaryPanel;
    private JDoubleBufferedPanel downBoundaryPanel;
    private TransparentPanel begginingPanel;
    private TransparentPanel centerPanel;

    public ArkanoidPanel(ArkanoidController arkanoidController) {
        this.arkanoidController = arkanoidController;
        this.setSize(new Dimension(width, height));
        this.setMinimumSize(new Dimension(width, height));
        this.setMaximumSize(new Dimension(width, height));
        this.setPreferredSize(new Dimension(width, height));
        this.setLayout(new BorderLayout(0, 0));
        initComponents();
    }

    private void initComponents() {
        begginingPanel = new TransparentPanel();
        begginingPanel.setSize(new Dimension(501, 80));
        begginingPanel.setMaximumSize(new Dimension(501, 80));
        begginingPanel.setMinimumSize(new Dimension(501, 80));
        begginingPanel.setPreferredSize(new Dimension(501, 80));
        begginingPanel.setBackground(Color.red);
        begginingPanel.setLayout(new GridLayout(1, 3, 0, 0));

        topBoundaryPanel = new JDoubleBufferedPanel();
        topBoundaryPanel.setSize(new Dimension(501, 18));
        topBoundaryPanel.setMaximumSize(new Dimension(501, 18));
        topBoundaryPanel.setMinimumSize(new Dimension(501, 18));
        topBoundaryPanel.setPreferredSize(new Dimension(501, 18));
        topBoundaryPanel.setBackground(Color.red);

        leftBoundaryPanel = new JDoubleBufferedPanel();
        leftBoundaryPanel.setSize(new Dimension(18, 449));
        leftBoundaryPanel.setMinimumSize(new Dimension(18, 449));
        leftBoundaryPanel.setMaximumSize(new Dimension(18, 449));
        leftBoundaryPanel.setPreferredSize(new Dimension(18, 449));
        leftBoundaryPanel.setBackground(Color.red);

        rightBoundaryPanel = new JDoubleBufferedPanel();
        rightBoundaryPanel.setSize(new Dimension(18, 449));
        rightBoundaryPanel.setMinimumSize(new Dimension(18, 449));
        rightBoundaryPanel.setMaximumSize(new Dimension(18, 449));
        rightBoundaryPanel.setPreferredSize(new Dimension(18, 449));
        rightBoundaryPanel.setBackground(Color.red);

        downBoundaryPanel = new JDoubleBufferedPanel();
        downBoundaryPanel.setSize(new Dimension(501, 18));
        downBoundaryPanel.setMinimumSize(new Dimension(501, 18));
        downBoundaryPanel.setMaximumSize(new Dimension(501, 18));
        downBoundaryPanel.setPreferredSize(new Dimension(501, 18));
        downBoundaryPanel.setBackground(Color.red);

        boardPanel = new JDoubleBufferedPanel();
        boardPanel.setSize(new Dimension(465, 585));
        boardPanel.setPreferredSize(new Dimension(465, 585));
        boardPanel.setMinimumSize(new Dimension(465, 585));
        boardPanel.setMaximumSize(new Dimension(465, 585));
        boardPanel.setVisible(true);
        boardPanel.setBackground(Color.black);

        lifePanel = new JDoubleBufferedPanel();
        lifePanel.setSize(new Dimension(167, 80));
        lifePanel.setPreferredSize(new Dimension(167, 80));
        lifePanel.setMinimumSize(new Dimension(167, 80));
        lifePanel.setMaximumSize(new Dimension(167, 80));
        lifePanel.setBackground(Color.LIGHT_GRAY);
        lifePanel.setLayout(new SpringLayout());
        lifePanel.setVisible(true);
        lifePanel.setBorder(BorderFactory.createLineBorder(Color.yellow));

        scorePanel = new JDoubleBufferedPanel();
        scorePanel.setSize(new Dimension(167, 80));
        scorePanel.setPreferredSize(new Dimension(167, 80));
        scorePanel.setMinimumSize(new Dimension(167, 80));
        scorePanel.setMaximumSize(new Dimension(167, 80));
        scorePanel.setBackground(Color.red);
        scorePanel.setVisible(true);
        scorePanel.setBorder(BorderFactory.createLineBorder(Color.BLUE));

        timePanel = new JDoubleBufferedPanel();
        timePanel.setSize(new Dimension(167, 80));
        timePanel.setPreferredSize(new Dimension(167, 80));
        timePanel.setMinimumSize(new Dimension(167, 80));
        timePanel.setMaximumSize(new Dimension(167, 80));
        timePanel.setBackground(Color.YELLOW);
        timePanel.setVisible(true);
        timePanel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

        centerPanel = new TransparentPanel();
        centerPanel.setSize(new Dimension(501, 621));
        centerPanel.setPreferredSize(new Dimension(501, 621));
        centerPanel.setMinimumSize(new Dimension(501, 621));
        centerPanel.setMaximumSize(new Dimension(501, 621));
        centerPanel.setLayout(new BorderLayout(0, 0));
        centerPanel.add(topBoundaryPanel, BorderLayout.PAGE_START);
        centerPanel.add(leftBoundaryPanel, BorderLayout.WEST);
        centerPanel.add(boardPanel, BorderLayout.CENTER);
        centerPanel.add(rightBoundaryPanel, BorderLayout.EAST);
        centerPanel.add(downBoundaryPanel, BorderLayout.AFTER_LAST_LINE);
        centerPanel.setVisible(true);

        begginingPanel.add(timePanel);
        begginingPanel.add(scorePanel);
        begginingPanel.add(lifePanel);

        this.setFocusable(true);
        this.add(begginingPanel, BorderLayout.PAGE_START);
        this.add(centerPanel, BorderLayout.CENTER);
        this.setVisible(true);
    }

    public JDoubleBufferedPanel getCanvas() {
        return boardPanel;
    }

    public JDoubleBufferedPanel getLifePanel() {
        return lifePanel;
    }

    public JDoubleBufferedPanel getScorePanel() {
        return scorePanel;
    }

    public JDoubleBufferedPanel getTimePanel() {
        return timePanel;
    }

    public JDoubleBufferedPanel getTopBoundaryPanel() {
        return topBoundaryPanel;
    }

    public JDoubleBufferedPanel getLeftBoundaryPanel() {
        return leftBoundaryPanel;
    }

    public JDoubleBufferedPanel getRightBoundaryPanel() {
        return rightBoundaryPanel;
    }

    public JDoubleBufferedPanel getDownBoundaryPanel() {
        return downBoundaryPanel;
    }
}
